﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TienLen
{
    /// <summary>
    /// The main menu, where the application loads this first.
    /// </summary>
    public partial class MainMenu : Form
    {
        private bool closeFrm = true; // The value if the application should exit

        public MainMenu()
        {
            InitializeComponent();

            lblVer.Text = "Tien Len Client Showcase v" + Application.ProductVersion;

            this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            Util.LoadCursor(this, CursorType.Default);

            optionButton.MouseLeave += new EventHandler(Button_MouseLeave);

            // Automatically add the main menu control to the menu panel.
            AddControl(new UC.MenuMain(this));
        }

        #region Properties

        /// <summary>
        /// The information textbox.
        /// </summary>
        public string InfoText
        {
            get { return infoTxtBox.Text; }
            set { infoTxtBox.Text = value; }
        }

        /// <summary>
        /// The menu panel.
        /// </summary>
        public Control MenuControl
        {
            get { return menucontain.Panel1.Controls[0]; }
        }

        /// <summary>
        /// The back button.
        /// </summary>
        public Button BackButton
        {
            get { return backButton; }
        }

        /// <summary>
        /// The option button.
        /// </summary>
        public Button OptionButton
        {
            get { return optionButton; }
        }

        /// <summary>
        /// Value if the form should or shouldn't close the whole application when the form closes.
        /// </summary>
        public bool SuppressExit
        {
            get { return !closeFrm; }
            set { closeFrm = !value; }
        }

        #endregion

        /// <summary>
        /// Add a control to the menu panel (top-right of form).
        /// </summary>
        /// <param name="control">The control to add.</param>
        internal void AddControl(Control control)
        {
            if (menucontain.Panel1.Controls.Count != 0) menucontain.Panel1.Controls[0].Dispose();
            menucontain.Panel1.Controls.Add(control);
        }

        internal void Button_MouseLeave(object sender, EventArgs e)
        {
            this.InfoText = string.Empty;
        }

        private void backButton_Click(object sender, EventArgs e)
        {
            if (MenuControl is UC.MenuMain)
                (MenuControl as UC.MenuMain).Back();

            else if (MenuControl is UC.MSNLogin)
            {
                AddControl(new UC.MenuMain(this));
                backButton.Visible = false;
            }
        }

        private void MainMenu_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (closeFrm) Application.Exit();
        }

        private void optionButton_Click(object sender, EventArgs e)
        {
            new Options().ShowDialog(this);
        }

        private void optionButton_MouseEnter(object sender, EventArgs e)
        {
            infoTxtBox.Text = "Change the game settings";
        }

        private void linkBlog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                System.Diagnostics.Process.Start(@"http://tienlen13.wordpress.com");
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                System.Diagnostics.Process.Start(@"http://www.pagat.com/climbing/thirteen.html");
        }
    }
}
